import router from '@/router/index'
import { useHomeRouters } from '@/stores/homeRouter';

import TeacherMange from '@/views/home/TeacherMange.vue';
import StudentMange from '@/views/home/StudentMange.vue';
import CourseMange from '@/views/home/CourseMange.vue';
import EvaluationMassage from '@/views/home/EvaluationMassage.vue';
import StudentInfo from '@/views/home/StudentInfo.vue';
export const addRoutersInHome = async()=>{
  const homeRouters = useHomeRouters();

  const routers = homeRouters.getHomeRouters();

  console.log('utils/router.js: addRoutersInHome',routers);


  for(let i=0;i<routers.length;i++){
    switch(routers[i].component){
      case 'TeacherMange':
        router.addRoute('home', { path: routers[i].path, component: TeacherMange })
        break;
      case 'StudentMange':
        router.addRoute('home',{ path: routers[i].path, component: StudentMange})
        break;
      case 'CourseMange':
        router.addRoute('home',{ path: routers[i].path, component: CourseMange})
        break;
      case 'EvaluationMassage':
        router.addRoute('home',{ path: routers[i].path, component: EvaluationMassage})
        break;
      case 'StudentInfo':
        router.addRoute('home',{ path: routers[i].path, component: StudentInfo})
    }
  }
  //持久化路由
  localStorage.setItem('homeRouters', JSON.stringify(routers))
}

export const gotoStudentManage = async()=>{
  await router.replace('/home/studentMange')
}

export const gotoStudentInfo = async()=>{
  await router.replace('/home/studentInfo')
}
